package cn.yunyichina.reservation.controller.console;

import cn.yunyichina.provider.framework.dubbo.service.ReservationService;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.reservation.common.ResponseEnum;
import cn.yunyichina.reservation.common.jackson.Jackson;
import cn.yunyichina.reservation.constant.HttpResponse;
import cn.yunyichina.reservation.constant.Interface;
import cn.yunyichina.reservation.util.RequestUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Lullaby on 2016/8/31.
 */
@RestController
@RequestMapping("console/order")
public class ConsoleOrderController {

    private static final String RESERVATION_ORDER_LIST = "yyt.reservation.order.list";

    @GetMapping("list")
    public HttpResponse listOrder(HttpServletRequest request) {
        HttpResponse httpResponse = new HttpResponse();
        Map<String, String> params = RequestUtil.getAllParameters(request);
        Response serviceResponse = ReservationService.callHumpFromInternal(
                RESERVATION_ORDER_LIST, Jackson.getBaseJsonData(params)
        );
        if (serviceResponse == null) {
            return httpResponse.failure(ResponseEnum.RPC_NOT_FOUND.getCode(), ResponseEnum.RPC_NOT_FOUND.getMessage());
        } else if (Interface.SUCCESS.equals(serviceResponse.getResultCode())) {
            httpResponse.setData(Jackson.getBeanJsonData(serviceResponse.getResult(), Map.class));
        } else {
            httpResponse.failure(ResponseEnum.RPC_EXCEPTION.getCode(), ResponseEnum.RPC_EXCEPTION.getMessage());
        }
        return httpResponse;
    }

}
